<template>
	<view class="order-index">
		<view class='header'>
			<view class='picTxt'>
				<view class='text'>
					<view class='name'>订单信息</view>
				</view>
				<view class='pictrue'>
					<image src='@/static/order/orderTime.png'></image>
				</view>
			</view>
		</view>
		<view class="lst-items" v-if="orderData.length>0">
			<block v-for="(item,index) in orderData" :key="index">
				<view class="item" style="margin-bottom: 20rpx;">
					<view class="hint-option center">
						<view class="time">{{timeFun(item.creation_time)}}</view>
						 <view class="state" style="border: 1px solid #cb3c28; padding: 8rpx 16rpx; border-radius: 60rpx;">{{stateTxt(item.status)}}</view>
					</view>
					<view class="detail-option">
						<block v-for="(shopItem,shopIndex) in item.commodityData"  :key="shopIndex">
							<view class="shop-item" @click="itemClick(shopItem.commodity_id,item.integral)">
								<view class="item-img">
									<image :src="shopItem.main_img" class="auto-img img-radius"></image>
								</view>
								<view class="item-info">
									<view class="title">{{shopItem.commodity_title}}</view>
									<view class="price center">
										<span>¥</span>{{shopItem.commodity_price/100}}
									</view>
								</view>
								<view class="count">X{{shopItem.count}}</view>
							</view>
						</block>
					</view>
					<view class="hint-price">共{{item.commodity_count}}件积分商品,积分<span>{{item.integral}}</span>
					</view>
					 
				</view>
			</block>
		</view>
		<template v-if="orderData.length==0">
			<view class="no-emty">暂无相关订单</view>
		</template>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page:0,
				orderData:[],
			}
		},
		onShow() {
			this.init()
		},
		computed: {
			stateTxt() {
				return item => {
					if (item == 0) {
						return '待兑换'
					}
					if (item == 1) {
						return '待兑换'
					}
					if (item == 2) {
						return '待兑换'
					}
					if (item == 3) {
						return '已兑换'
					}
					if (item == 10) {
						return '交易已关闭'
					}
				}
			},
			timeFun() {
				return time => {
					return this.getDate(time)
				}
			}
		},
		methods: {
			itemClick(id,integral) {
				console.log(123,id,integral)
				uni.setStorageSync('integral',integral)
				uni.navigateTo({
					url: '/pages/shopDetail/shopDetail?goodsId=' + id + '&type=2'
				})
			},
			init(){
				this.orderData=[]
				this.$http('order.queryIntegralOrder',{
					token:this.$tools.getToken(),
					page:this.page,
				}).then(res=>{
					if(res.code==200){
						var orderData = res.data.orderBasic;
						var orderCommodityData = res.data.orderCommodity;
						for (let var1 in orderData) {
							var commodityData = [];
							for (let var2 in orderCommodityData) {
								if (orderCommodityData[var2].order_id == orderData[var1].id) {
									commodityData.push(orderCommodityData[var2])
								}
							}
							orderData[var1].commodityData = commodityData;
							this.orderData.push(orderData[var1])
						}
					}
					console.log('res',res)
				})
			}
		}
	}
</script>


<style>
	page {
		background: #FAFAF5FF;

	}
</style>
<style lang="scss" scoped>
	.order-index {
		padding-bottom: 50rpx;
	}

	.header {
		height: 166rpx;
		padding: 0 30rpx;
		background: #e93323;

	}

	.picTxt {
		height: 190rpx;
		display: flex;
		align-items: center;
	}

	.text {
		flex: auto;
		color: rgba(255, 255, 255, 0.8);
		font-size: 26rpx;
	}

	.name {
		font-size: 34rpx;
		font-weight: bold;
		color: #fff;
		margin-bottom: 20rpx;
	}

	.pictrue {
		flex: none;
		width: 122rpx;
		height: 109rpx;
	}

	.pictrue image {
		width: 100%;
		height: 100%;
	}

	.lst {
		margin-right: 32rpx;
		margin-left: 32rpx;
		margin-top: -100rpx;
		border-radius: 8rpx;
		background: #fff;
		padding: 24rpx 0;
		display: flex;
		align-items: center;
		justify-content: space-evenly;

		font-size: 28rpx;
		color: #282828;


		.item {
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;

			.txt {}

			.nums {
				margin-top: 24rpx;
			}
		}

		.check-item {
			font-weight: bold;
		}

	}

	.lst-items {
		margin-right: 32rpx;
		margin-left: 32rpx;
		margin-top: 24rpx;
		border-radius: 8rpx;
		background: #fff;
		padding: 0 24rpx 20rpx 24rpx;

		.hint-option {
			padding: 24rpx 0;
			font-size: 28rpx;

			.time {
				flex: auto;
				color: rgba(27, 25, 25, 1);
			}

			.state {
				flex: none;
				color: rgba(203, 60, 40, 1);
			}
		}

		.detail {
			padding: 24rpx 0;
			border-bottom: 2rpx solid #F5F5FF5;

		}

		.hint-price {
			margin-top: 24rpx;
			font-size: 28rpx;
			display: flex;
			align-items: center;
			justify-content: flex-end;

			span {
				color: rgba(203, 60, 40, 1);
			}
		}

		.btn-option {
			display: flex;
			align-items: center;
			justify-content: flex-end;
			font-size: 26rpx;
			padding: 24rpx 0;

			.btn {
				margin-left: 18rpx;
				width: 176rpx;
				height: 60rpx;
				line-height: 60rpx;
				text-align: center;
				border-radius: 728rpx;
			}

			.cancel {
				height: 59rpx;
				width: 175rpx;
				color: #aaa;
				border: 1rpx solid #aaa;
			}

			.pay {
				color: #fff;
				background: rgba(203, 60, 40, 1);
			}
		}
	}

	.shop-item {
		margin-top: 32rpx;
		display: flex;
		align-items: flex-start;

		.item-img {
			flex: none;
			border-radius: 8rpx;
			width: 140rpx;
			height: 140rpx;
		}

		.item-info {
			flex: auto;
			margin-left: 20rpx;

			.title {
				font-size: 28rpx;
				font-weight: 400;
				color: rgba(27, 25, 25, 1);
				line-height: 1.5em;
			}

			.price {
				color: rgba(199, 44, 30, 1);
				font-size: 32rpx;
				font-weight: 700;
				margin-top: 12rpx;

				span {
					font-size: 22rpx;
				}
			}
		}

		.count {
			padding-left: 90rpx;
			flex: none;
			font-size: 28rpx;
			font-weight: 400;
			color: rgba(153, 153, 153, 1);
		}
	}

	.no-emty {
		display: flex;
		align-items: center;
		justify-content: center;
		margin-top: 40rpx;
		font-size: 26rpx;color: #999;
		// background: #f5f5f5;
	}
</style>
